#!/bin/bash

HERE="$(dirname "$(readlink -f "${0}")")"

if [ ! -e /etc/udev/rules.d/50-arduino.rules ] ; then
cat > /tmp/roothelper <<\EOoF
#!/bin/bash
cat > /etc/udev/rules.d/50-arduino.rules <<\EOF
SUBSYSTEM=="tty", KERNEL=="ttyUSB[0-9]*|ttyACM[0-9]*", GROUP="users", MODE="0666"
EOF
udevadm trigger
EOoF
chmod a+x /tmp/roothelper
sudo true && sudo /tmp/roothelper
sudo true || pkexec --disable-internal-agent /tmp/roothelper || true
rm /tmp/roothelper
fi

"$HERE/usr/bin/arduino" "$@"
